<template>
	<view>
		<!-- <template>
		<view class="historyModel">
			<view class="title"><text>搜索历史记录</text></view>
			<view class="historyList">
				<view>一giao窝里giaogiao</view>
				<view>一giao窝里giaogiao</view>
			</view>
			<view class="clear"><text>清除所有历史</text></view>
		</view>
		</template> -->
		<view class="historyModel">
		<view class="title"><text>搜索结果：</text></view>
		
		<view class="searchList">
			<template v-if="result == 1">
			<block v-for="(item,index) in searchList" :key="index">
				<text @tap="toFarm(index)">{{item.farm_name}}</text>
			</block>
			</template>
			<template v-else-if="result == 2" >
				<text>没有查到哦</text>
			</template>
		</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputText:"",
				historyList:'',
				searchList:'',
				result:''
			};
		},
		//监听搜索框内容
		onNavigationBarSearchInputChanged(e){
			this.inputText = e.text;
		},
		//键盘搜索
		onNavigationBarSearchInputConfirmed(){
			this.search()
		},
		//监听按钮点击事件
		onNavigationBarButtonTap(){
			this.search()
		},
		onNavigationBarSearchInputClicked() {
			console.log(e)
		},
		onReady() {
			// this.getStorage();
			this.result=''
		},
		methods:{
			getStorage(){
			this.historyList = uni.getStorageSync('historyList');
			console.log(this.historyList)
			},
			//前往养殖场
			toFarm(index){
			let farmId = this.searchList[index].farm_id;
			uni.navigateTo({
				url:"../government/farmerDetails?farmId="+farmId
			})
			},
			//搜索
			search(){
				if(!this.inputText){ uni.showToast({
					icon:"none",
					title:"内容不能为空"
				});return;}
				if(this.inputText.length==1||this.inputText==="养殖"||this.inputText==="养殖场"){ 
					uni.showModal({
						title:"提示",
						content:"为提高搜索效率，请输入xx养殖场以便检索",
						showCancel:false
					})
				return;}
				uni.showLoading({
					title:"搜索中...."
				})
				uni.request({
					url:this.confige.webUrl+"/aquaculture/checkFarm",
					data:{
						farm_name:this.inputText
					},
					header:{
						'X-Token':this.User.token
					},
					success: (res) => {
						console.log(res);
						
							uni.hideLoading();
						
						if(res.data.code == 200){
						this.searchList = res.data.result;
						this.result = 1;
						}
						else if (res.data.code == 400 ){
							this.result = 2;
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
.historyModel{
	width: 100%;
	.title{
		padding:20rpx ;
		font-size: 28rpx;
		color: #C9C9C9;
	}
	.historyList{
		min-height: 150rpx;
		>view{
			width:85%;
			margin:auto;
			font-size:32rpx;
			padding: 5rpx;
			color:#B8B8B8 ;
			}
	}
	.searchList{
		   >text{
			   margin:10rpx;
		   }
		    display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			width:85%;
			margin:auto;
			font-size:32rpx;
			padding: 5rpx;
			color:#333333;
	}
	.clear{
		text-align: right;
		margin-right: 20rpx;
		font-size: 30rpx;
		color: #65AAC5;
		text{
		border-bottom: 1rpx solid #65AAC5;
		margin-bottom: 1rpx;
		}
	}
}
</style>
